package br.com.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import br.com.biblioteca.Book;
import br.com.biblioteca.BookList;
import br.com.carrinho.ShoopingCart;



@WebServlet("/Adicionar.do")
public class AddToCartServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       

    public AddToCartServlet() {
        super();
       
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		PrintWriter out = response.getWriter();
		String codigo =request.getParameter("logica");	
		BookList lista = BookList.getSingleton();	
		Book livro = lista.getBook(codigo);
		
		
		HttpSession session = request.getSession();
		session.setAttribute("usuario",ShoopingCart.getShopping());
		
		ShoopingCart cart = (ShoopingCart) session.getAttribute("usuario");
		
		cart.add(livro);
		
		out.print("livro"+livro.getTitle()+" adicionado!");
		out.print("<a href='Verificar.do'>Verificar lista</a>");
	
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
	}

}
